//----------------------------------*-C++-*----------------------------------//
/*!
 * \file   Serment.cc
 * \author Jeremy Roberts
 * \date   11/05/2010
 * \brief  Driver for Serment
 * \note   Copyright (C) 2010 Jeremy Roberts
 */
//---------------------------------------------------------------------------//
// $Rev:: 140                                           $:Rev of last commit
// $Author:: j.alyn.roberts@gmail.com                   $:Author of last commit
// $Date:: 2011-09-14 16:53:40 +0000 (Wed, 14 Sep 2011) $:Date of last commit
//---------------------------------------------------------------------------//

#include <iostream>
#include <cmath>
#include "LinAlg.hh"
#include "GlobalInput.hh"
#include "ResponseFunctionServer.hh"
#include "ResponseMatrix.hh"
#include "ResponseMatrixFull.hh"
#include "AbsorptionResponse.hh"
#include "FissionResponse.hh"
#include "LeakageResponse.hh"
#include "ConnectMatrix.hh"
#include "Connect2dCart.hh"
#include "GlobalProblem.hh"
#include "GlobalSolver.hh"
#include "PowerIter.hh"
#include "Newton.hh"
#include "utilities/GenException.hh"

using namespace std;

//---------------------------------------------------------------------------//

int main(int argc, char *args[])
{

    if ( argc < 2 )
	{
		throw GenException(__LINE__,__FILE__,
                           "Need at least 1 command line argument.");
	}
    
    // initialize petsc
    PetscInitialize(&argc,&args,PETSC_NULL,PETSC_NULL);
    scalar tTOT = MPI_Wtime();

    // global input with the grammar as an argument
    GlobalInput input("serment.rng");

	if ( !input.readInput( args[1] ) )
	{
		cout << " input error...goodbye " << endl;
		return 0;
	}
	input.echoInput();

    // create the server; she decides to/from whom rf's go/come
    ResponseFunctionServer *s = new ResponseFunctionServer( input );

    GlobalProblem gp( input, s );

    scalar tPI=0.0, tN=0.0;

	// PI solve
    tPI = MPI_Wtime();
    if (input.pctype==-1)
    {
        PowerIter solver( gp, input );
        solver.Solve();
    }
    tPI = MPI_Wtime()-tPI;

	// Newton solve
    tN = MPI_Wtime();
    if (input.pctype>=0)
    {
        Newton solver2( gp, input );
        solver2.Solve();
    }
    tN = MPI_Wtime() - tN;
    tTOT = MPI_Wtime()-tTOT;

    std::cout << "  PI     Time: " << tPI << std::endl;
    std::cout << "  Newton Time: " << tN << std::endl;
    std::cout << "  Server Time: " << s->serverTime() << std::endl;
    std::cout << "  Total  Time: " << tTOT << std::endl;

	PetscFinalize();

	std::cout << "  ... te ootte nyt menneet loppuun " << std::endl;

    return 0;
}

//---------------------------------------------------------------------------//
//                 end of Serment.cc
//---------------------------------------------------------------------------//

